package com.ruoyi.constituent.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SNUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.constituent.domain.ConstituentDetail;
import com.ruoyi.constituent.service.IConstituentDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成分明细Controller
 * 
 * @author weihanqiang
 * @date 2025-09-16
 */
@RestController
@RequestMapping("/constituent/detail")
public class ConstituentDetailController extends BaseController
{
    @Autowired
    private IConstituentDetailService constituentDetailService;

    @Autowired
    private SNUtil snUtil;

    /**
     * 查询成分明细列表
     */
    @PreAuthorize("@ss.hasPermi('constituent:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConstituentDetail constituentDetail)
    {
        startPage();
        List<ConstituentDetail> list = constituentDetailService.selectConstituentDetailList(constituentDetail);
        return getDataTable(list);
    }

    /**
     * 导出成分明细列表
     */
    @PreAuthorize("@ss.hasPermi('constituent:detail:export')")
    @Log(title = "成分明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConstituentDetail constituentDetail)
    {
        List<ConstituentDetail> list = constituentDetailService.selectConstituentDetailList(constituentDetail);
        ExcelUtil<ConstituentDetail> util = new ExcelUtil<ConstituentDetail>(ConstituentDetail.class);
        util.exportExcel(response, list, "成分明细数据");
    }

    /**
     * 获取成分明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('constituent:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(constituentDetailService.selectConstituentDetailById(id));
    }

    /**
     * 新增成分明细
     */
    @PreAuthorize("@ss.hasPermi('constituent:detail:add')")
    @Log(title = "成分明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConstituentDetail constituentDetail)
    {
        return toAjax(constituentDetailService.insertConstituentDetail(constituentDetail));
    }

    /**
     * 修改成分明细
     */
    @PreAuthorize("@ss.hasPermi('constituent:detail:edit')")
    @Log(title = "成分明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConstituentDetail constituentDetail)
    {
        return toAjax(constituentDetailService.updateConstituentDetail(constituentDetail));
    }

    /**
     * 删除成分明细
     */
    @PreAuthorize("@ss.hasPermi('constituent:detail:remove')")
    @Log(title = "成分明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(constituentDetailService.deleteConstituentDetailByIds(ids));
    }
}
